<?php

namespace App\Http\Controllers\Backstage;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
class ClearController extends BCommonController
{
    public function index()
    {
        //清除缓存
        $dirs = array(
            storage_path('framework/cache'),
            // storage_path('framework/sessions'),//登录状态相关
            storage_path('framework/views'),
        );
        foreach($dirs as $value)
        {
            if(file_exists($value))
            {
                $this->to_rmdir($value);
                echo "<div style='border:2px solid #999999; background:#fcf8e3; padding:20px;margin:20px;width:800px;font-weight:bold;color:green;text-align:center;'>\"".$value."\" 目录下缓存清除成功! </div> <br /><br />";
                @mkdir($value,0755,true);
            }

        }
    }

    public function to_rmdir($dirname)
    {
        if (!file_exists($dirname))
        {
            return false;
        }
        if (is_file($dirname) || is_link($dirname)) 
        {
            return unlink($dirname);
        }
        $dir = dir($dirname);
        while (false !== $entry = $dir->read()) 
        {
            if ($entry == '.' || $entry == '..') 
            {
                continue;
            }
            $this->to_rmdir($dirname . DIRECTORY_SEPARATOR . $entry);
        }
        $dir->close();
        return rmdir($dirname);
    }
    
    
    
    
    
}














   

    

